; (function () {
	function getNextDate(date,day) {  
	  var dd = new Date(date);
	  dd.setDate(dd.getDate() + day);
	  var y = dd.getFullYear();
	  var m = dd.getMonth() + 1 < 10 ? "0" + (dd.getMonth() + 1) : dd.getMonth() + 1;
	  var d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
	  return y + "-" + m + "-" + d;
	}
  new Vue({
    el: '#report_bi',
    data: {
      listMenu: [
				{
				  'name':'单元维度',
				  'code':'BU'
				},
				{
				  'name':'工位维度',
				  'code':'WP'
				},
				{
				  'name':'车位维度',
				  'code':'ST'
				},
			],
			selectedStarProject: ['BU'],
			payment_begin_time: getNextDate(hlDateUtil.formatUTCDate(new Date().getTime(), 'yyyy-MM-dd'), -1),
			totalCount: 0,
			pageCounts: [{name: '10', code: '10'}, {name: '15', code: '15'}, {name: '20', code: '20'}],

      limit: ['10'],
      currentPage: 1,
      totalPage: 0,
      isExtenseFlag:false,
      quanxian: JSON.parse(window.localStorage.getItem('permissions')),
			
			unitData: [],
			stwpData: []
    },
    filters: {
      
      formatDate: function (time) {
        if (time === undefined) return '--'
        return hlDateUtil.formatUTCDate(time, 'yyyy-MM-dd')
      },
    },
    methods: {
			getUnitData () {
				hlhttp.get({
					url: 'report/unit/operate_status/report',
					data: {report_date: this.payment_begin_time},
					success: (data) => {
						this.unitData = data;
					}
				})
			},
			get_stwpData () {
				hlhttp.get({
					url: 'report/position/operate_status/report',
					data: {report_date: this.payment_begin_time, type: this.selectedStarProject.toString()},
					success: (data) => {
						this.stwpData = data;
					}
				})
			},			
			selectStarPro(item){
				if (item.includes('BU')) {
					this.getUnitData()
				} else {
					this.get_stwpData()
				}
			},
			pagination () {
				if (this.selectedStarProject.includes('BU')) {
					this.getUnitData()
				} else {
					this.get_stwpData()
				}
			},
      //分页
      selectPerNum(arr) {
        this.limit = [arr[0].code];
				if (this.selectedStarProject.includes('BU')) {
					this.getUnitData()
				} else {
					this.get_stwpData()
				}
      },
      //导出文件
      incomeExport() {
        hlhttp.get({
          baseUrl: exclUrl,
          url: 'resource/operate_status_export',
          data: {
            report_date:  this.payment_begin_time,
						type: this.selectedStarProject.toString()
          },
          success: (data) => {
            var a = document.createElement('a');
            a.href = data.excel_url;
            $('body').append($(a))
            a.click();
            setTimeout(function() {
              $(a).remove()
            }, 100);

          }
        })
      },

    },
    created() {
     this.getUnitData()
    },
    mounted() {
      
    }
  })

  function compareAsc(propertyName) {
    return function (object1, object2) {
      var value1 = object1[propertyName];
      var value2 = object2[propertyName];
      if (value2 < value1) {
        return 1;
      } else if (value2 > value1) {
        return -1;
      } else {
        return 0;
      }
    }
  }
}())
